package PostBar.Data;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class GetSignBar {
	private String cookie=null;
	private String[] kwArray= new String[10000];
	private int data=0;
	private final String frisrweb="http://tieba.baidu.com/";
	public GetSignBar(String cookie){
		this.cookie=cookie;
	}
	public String[] getkw() {
		try {
			URL url = new URL(frisrweb);
			HttpURLConnection httpURLConnection =(HttpURLConnection)url.openConnection();
			System.out.println(cookie);
			httpURLConnection.setRequestProperty("Cookie", cookie);
			httpURLConnection.setDoInput(true);
			httpURLConnection.setDoOutput(true);
			httpURLConnection.connect();
			InputStreamReader ios = new InputStreamReader(httpURLConnection.getInputStream(),"GBK");
			BufferedReader bwReader=new BufferedReader(ios);
			String line=null;
			while ((line=bwReader.readLine())!=null) {
			
				if (line.contains("_.Module.use")) {
					System.out.println(line);
					Pattern pattern = Pattern.compile("\"forum_name\":\"(.*?)\"");
					Matcher matcher = pattern.matcher(line);
					while(matcher.find())
					{ 
						String temp=matcher.group();
						temp=temp.substring(temp.indexOf(":")+2,temp.length()-1);
						kwArray[data]=temp;
						data++;
					}
				}
			}
		} catch (MalformedURLException e) {
		
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return kwArray;
	}

}
